//
//  NKTabBarController.m
//  NiKi
//
//  Created by qiang chen on 16/6/20.
//  Copyright © 2016年 qiang chen. All rights reserved.
//

#import "NKTabBarController.h"
#import "NKTabBar.h"
#import "OXNavigationController.h"
#import "NKHomeViewController.h"
#import "NKListenController.h"
#import "NKBabyController.h"
#import "NKParentController.h"

@interface NKTabBarController ()<NKTabBarDelegate>

@end

@implementation NKTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupChildVc];
    
    [[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:@"图层-0"]];
    [[UITabBar appearance] setShadowImage:[UIImage new]];
        
    NKTabBar *aTabBar = [[NSBundle mainBundle]loadNibNamed:NSStringFromClass([NKTabBar class]) owner:nil options:nil].lastObject;
    aTabBar.delegate = self;
//    self.aTabBar.frame = CGRectMake(0, ScreenH - kTabBarH, ScreenW, kTabBarH);
    aTabBar.frame = CGRectMake(0, 49-kTabBarH, ScreenW, kTabBarH);
    
    [self.tabBar addSubview:aTabBar];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    // 移除系统UITabBar上自带的按钮
    for (UIView *childView in self.tabBar.subviews) {
        // 判断下是否是UITabButton
        if ([childView isKindOfClass:[NKTabBar class]] == NO) {
            
            [childView removeFromSuperview];
        }
    }
}

- (void)setupChildVc {
    NKHomeViewController *homeVC = [[NKHomeViewController alloc]init];
    OXNavigationController *homeNav = [[OXNavigationController alloc]initWithRootViewController:homeVC];
    
    NKListenController *listenVC = [[NKListenController alloc]init];
    listenVC.type = ControllerType_Listen;
    OXNavigationController *listenNav = [[OXNavigationController alloc]initWithRootViewController:listenVC];
    
    NKBabyController *babyVC = [[NKBabyController alloc]init];
    OXNavigationController *babyNav = [[OXNavigationController alloc]initWithRootViewController:babyVC];
    
    NKParentController *parentVC = [[NKParentController alloc]init];
    OXNavigationController *parentNav = [[OXNavigationController alloc]initWithRootViewController:parentVC];
    
    NKListenController *moiveVc = [[NKListenController alloc]init];
    moiveVc.type = ControllerType_See;
    OXNavigationController *moiveNav = [[OXNavigationController alloc]initWithRootViewController:moiveVc];
    
    self.viewControllers = @[babyNav,listenNav,homeNav,moiveNav,parentNav];
}


- (void)tabBar:(NKTabBar *)tabBar didClickBtn:(NSInteger)buttonIndex {
    self.selectedIndex = buttonIndex;
}


@end
